package com.tsystems.train.bean;

import java.io.Serializable;
import java.util.List;

import javax.faces.model.ListDataModel;

import org.primefaces.model.SelectableDataModel;

import com.tsystems.train.entity.User;

public class UserTableDataModel extends ListDataModel<User> implements
		SelectableDataModel<User>, Serializable {

	private static final long serialVersionUID = 7887499387669171865L;

	public UserTableDataModel() {
	}

	public UserTableDataModel(List<User> data) {
		super(data);
	}

	@SuppressWarnings("unchecked")
	public User getRowData(String rowKey) {
		List<User> users = (List<User>) getWrappedData();

		for (User user : users) {
			String key = user.getLogin();
			if (key.equals(rowKey))
				return user;
		}

		return null;
	}

	public Object getRowKey(User user) {
		return user.getLogin();
	}
}
